using SharePoint.Security.ConfigAnalyzer.Engine.Base;
using SharePoint.Security.ConfigAnalyzer.Engine.Common;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint.Administration;
using RuleInfo = SharePoint.Security.ConfigAnalyzer.Engine.Common.RuleInfo;

namespace SharePoint.Security.ConfigAnalyzer.Engine.Rules.SearchAdmin
{
    public class IgnoreSSLWarnings : BaseRule
    {
        #region Overrides of BaseRule

        public IgnoreSSLWarnings()
        {
            RuleInfo = new RuleInfo
                           {
                               Description = "Uncheck the Ignore SSL certificate name warnings in SSL Certificate Warning Configuration  (Central Administration > Application Management > Search Service > Farm-Level Search Settings)",
                               Title = "Ignore SSL Warnings",
                               ExpectedValue = "False"
                           };
        }

        public override void Validate()
        {
            foreach (SPService service in ObjectHelper.Farm.Services)
            {
                if (!(service is SearchService)) continue;

                var searchService = (SearchService)service;

                if (!searchService.IgnoreSSLWarnings)
                {
                    Status = Status.Pass;;
                }
                else
                {
                    Status = Status.Fail; ;
                }

                CurrentValue = searchService.IgnoreSSLWarnings.ToString();
                break;
            }

        }

        #endregion
    }
}